#!/bin/bash

#************************************************#
#           Initialization Script                #
#            written by CainGao                  #
#                 Feb 24, 2020                   #
#                                                #
#        Initialize pentagon Configurations      #
#************************************************#

###源码目录
source_dir=/ROOT/tmps/build
### 部署目录
www_dir=/ROOT/www/
####  下载/更新 源码
if [[ ! -d $source_dir/anydata ]];then
  mkdir -p $source_dir
  git clone https://gerylove5927%40qq.com:Gaoweigong1991@gitee.com/xizhuo/anydata.git $source_dir/anydata
else
  cd $source_dir/anydata
  git pull
fi
### 编译代码
mvn clean package -DskipTests
### 移动并重命名到指定位置
mv /ROOT/tmps/build/anydata/pentagon/target/pentagon*.jar /ROOT/www/pentagon.jar
### 杀掉java进程
pid=`ps -ef|grep "pentagon"|grep -v grep|awk '{print $2}'`
if [ -n "$pid" ]; then
  kill -9 $pid
fi
### 启动服务
echo '启动服务..'
nohup java -jar /ROOT/www/pentagon.jar --spring.profiles.active=prod >/dev/null 2>&1 &
